<?php

class HmEvent_HmCommentsController extends Fw_Main
{
	public function addAction()
	{
		$id = (int)$this->_request->getParam('id');
		if($this->_request->isPost()) {
			$formData = $this->_request->getPost('add');
			if($formData) {
				$data = array(
							  'name' => $this->_request->getPost('name'),
							  'email' => $this->_request->getPost('email'),
							  'url' => $this->_request->getPost('url'),
							  'message' => $this->_request->getPost('message'),
							  'hm_event_id' => $id,
							  'date_register' => date('Y-m-d H:i:s')
							  );
				$_model = $this->_getModel('HmEventComments');
				$list_post = $_model->addRow($data);
				$this->_redirector = $this->_helper->getHelper('Redirector');
				$this->_redirector->gotoSimple('view','hm-event','hm-event',array('id' => $id));
        		return;
			}
		}
	}
	
	public function commentsAction()
	{
		$id = (int)$this->_request->getParam('id');
		$_model = $this->_getModel('HmEventComments');
		$list_post = $_model->getAll($id);
		$this->view->list_post = $list_post;
		$this->view->postcount = count($list_post);
	}
	
	public function deleteAction()
	{
		$this->validateUser();
		$id = (int)$this->_request->getParam('comment_id');
		$entry_id = (int)$this->_request->getParam('id');
		$_model = $this->_getModel('HmEventComments');
		$delete_post = $_model->deleteRow($id, $entry_id);
		return $this->_helper->redirector('comments');
	}
}